package com.swallow.auth.domain.dept.model.entity;

import com.swallow.auth.common.enums.ErrorCode;
import com.swallow.auth.common.exception.BizException;
import com.swallow.auth.common.utils.SpringUtils;
import com.swallow.auth.domain.dept.repository.IDeptDomainRepository;
import com.swallow.auth.domain.uniqno.NumWorker;
import com.swallow.auth.domain.uniqno.model.entity.BizNoValObj;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author: 18310740596@163.com
 * @date: 2024-05-20 21:57:36
 * @version: v1.0
 * @describe: class responsibility
 */
@Builder
@Accessors(chain = true)
@Data
public class DeptEntity {
    private String tenantNo;

    /**
     *  部门编号
     */
    private String deptNo;

    /**
     *  部门名称
     */
    private String deptName;
    /**
     *  父级部门编号
     */
    private String parentDeptNo;

    /**
     *  部门层级
     */
    private Integer level;

    /**
     *  删除标识
     */
    private Long deleteFlag;

    /**
     *  名字重复性校验
     */
    public void nameRepeatCheck() {
        IDeptDomainRepository repository = SpringUtils.getBean(IDeptDomainRepository.class);
        Boolean hasRepeat = repository.nameRepeatCheck(this);

        if (hasRepeat) {
            throw new BizException(ErrorCode.DATA_HAS_EXITS, "部门名称");
        }
    }

    /**
     *  创建
     */
    public void create() {
        IDeptDomainRepository repository = SpringUtils.getBean(IDeptDomainRepository.class);
        setDeptNo(NumWorker.bizNo(BizNoValObj.DEPT_NO));
        repository.create(this);
    }

    /**
     *  判断是否存在子部门
     */
    public void hasContainsSubDept() {

    }

    public void hasContainsEmp() {

    }
}
